package com.ssy.lingxi.sms.repository;

import com.ssy.lingxi.sms.entity.SmsConfig;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

/**
 * 腾讯云短信服务持久化层
 * @author jw.chen
 * @version 2.0.0
 * @date 2020/6/11
 */
public interface SmsConfigRepository extends JpaRepository<SmsConfig,Long>, JpaSpecificationExecutor<SmsConfig> {

    SmsConfig findTopByServiceTypeOrderByIdDesc(Integer serviceType);

    SmsConfig findSmsConfigByStatus(Boolean status);

    @Transactional
    @Modifying(clearAutomatically = true)
    @Query("update SmsConfig sc set sc.status = false where sc.id <> :id")
    int stopOthersConfig(long id);

}
